<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.User" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>历史订单查询</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/orderQuery.css">
</head>
<body>
<%@ include file="userNavbar.jsp" %>

<div class="order-card mt-16">
    <h1 class="text-3xl font-bold text-gray-800 mb-6 text-center">历史订单查询</h1>
    <%
        User user = (User) session.getAttribute("user");
        if (user != null) {
            List<String> input = new java.util.ArrayList<>();
            // 这里可以根据实际需求添加查询条件
            List<String> orders = user.Historical_orders(input);
            if (orders != null && !orders.isEmpty()) {
    %>
    <table class="min-w-full divide-y divide-gray-200">
        <thead class="bg-gray-50">
            <tr>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">订单号</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">用户 ID</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">航班 ID</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">订票时间</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">支付金额</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">订单状态</th>
            </tr>
        </thead>
        <tbody class="bg-white divide-y divide-gray-200">
            <%
                for (String order : orders) {
                    String[] orderFields = order.split(",");
            %>
            <tr>
                <td class="px-6 py-4 whitespace-nowrap">
                    <%= orderFields[0] %>
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <%= orderFields[1] %>
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <%= orderFields[2] %>
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <%= orderFields[3] %>
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <%= orderFields[4] %>
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <%= orderFields[5].equals("0") ? "未支付" : "已支付" %>
                </td>
                <td class="px-6 py-4 whitespace-nowrap">
                    <form action="PaymentServlet" method="post">
                        <input type="hidden" name="oid" value="<%= orderFields[0] %>">
                        <input type="hidden" name="payamount" value="<%= orderFields[4] %>">
                        <input type="hidden" name="aid" value="<%= orderFields[2] %>">
                        <button 
                            type="submit" 
                            class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
                            <%= orderFields[5].equals("0") ? "" : "disabled" %>
                        >
                            <%= orderFields[5].equals("0") ? "支付" : "已支付" %>
                        </button>
                    </form>
                </td>
            </tr>
            <%
                }
            %>
        </tbody>
    </table>
    <%
            } else {
    %>
    <p class="text-center text-gray-600">暂无历史订单。</p>
    <%
            }
        } else {
    %>
    <p class="text-center text-red-600">未获取到用户信息，请重新登录。</p>
    <%
        }
    %>
</div>
</body>
</html>